<template>
  <view>
    <view>
      <u-notice-bar :text="text1"></u-notice-bar>
    </view>
    <!--       <u&#45;&#45;text type="warning" style="text-align: center" text="注：正与推荐人进行绑定关系，谨慎操作！"></u&#45;&#45;text>-->
    <u-modal :show="show" :title="title" @confirm="confirm" ref="uModal" :asyncClose="true">
      <view class="slot-content">
        <rich-text :nodes="content"></rich-text>
      </view>
    </u-modal>

    <view class="b-btn">
      <!--      <u-button @click="showModal" type="primary">确认</u-button>-->
      <view class="tac colorf Btn matp" @click="showModal">确认</view>
    </view>
  </view>
</template>

<script>
import {
  modify,
  getUserInfo
} from "../../api/setting.js"
import tabbar from "../../components/tabbar/tabbar.vue"
import config from '@/common/config'
import {
  bindingCheckUser,
  bindingUser
} from "../../api/index";
export default {
  data() {
    return {
      text1: "注：正与推荐人确认推荐关系！",
      show: false,
      showNotify: true,
      title: '提示',
      content: '',
      scene: '',
      imguser: config.baseImgUrl
    }
  },
  onShow() {
    // this.getMessage()
    // this.tabBerLists = uni.getStorageSync('tabBarList') // 自定义的tabbar赋值
  },
  onLoad(query) {
    //scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
    const scene = decodeURIComponent(query.scene)
    console.log("scene2:" + scene);
    this.scene = scene
  },
  methods: {
    // 获取用户信息
    getMessage() {
      getUserInfo().then(res => {
        this.user = res.data
      })
    },
    showModal() {
      bindingCheckUser(this.scene).then(res => {
        if (res.data.code === 200) {
          this.content = res.data.data
          this.show = true;
        } else {
          uni.$u.toast(res.data.message)
        }
      })
    },
    confirm() {
      //绑定确认
      bindingUser(this.scene).then(res => {
        console.log(res)
        if (res.data.code === 200) {
          uni.$u.toast("操作成功！")
          this.show = false;
          setTimeout(() => {
            uni.switchTab({
              url: '/pages/index/index'
            })
          }, 1000)
        } else {
          this.show = false;
          uni.$u.toast(res.data.message)

        }
      })
      // setTimeout(() => {
      //   // 3秒后自动关闭
      //   this.show = false;
      // }, 1500)
    }
  }
}
</script>

<style lang="scss" scoped>
.b-btn {
  margin-top: 50%;
  width: 50%;
  margin-left: 25%;

}

.Btn {
  line-height: 110rpx;
  border-radius: 6rpx;
  background-color: #0055ff;
}

.matp {
  margin-top: 40rpx;
}
</style>